package com.example.project.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.project.R;
import com.example.project.bean.AccountBean;
import com.example.project.bean.YearDetail;

import java.util.Calendar;
import java.util.List;

public class YearBillAdapter  extends BaseAdapter {
    Context context; //上下文对象
    List<YearDetail> mDatas; //列表
    LayoutInflater inflater; //布局填充器
    int year,month,day; //年月日

    public YearBillAdapter(Context context, List<YearDetail> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
        inflater = LayoutInflater.from(context);
        //获取当前时间，年月日
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH)+1;
        day = calendar.get(Calendar.DAY_OF_MONTH);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        YearBillAdapter.ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate( R.layout.item_year_month,parent,false);
            holder = new YearBillAdapter.ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (YearBillAdapter.ViewHolder) convertView.getTag();
        }
        YearDetail bean = mDatas.get(position);
        holder.tvmonth.setText(bean.getMonth()+"月");
        holder.tvIn.setText(bean.getInmoney()+"");
        holder.tvOut.setText(bean.getOutmoney()+"");
        holder.tvBalance.setText(""+bean.getYuer());
        return convertView;
    }



    class ViewHolder{
        ImageView ivmonth;
        TextView tvmonth,tvIn,tvOut,tvBalance;
        public ViewHolder(View view){
            ivmonth = view.findViewById( R.id.iv_month);
            tvmonth = view.findViewById( R.id.tv_month);
            tvIn = view.findViewById( R.id.tv_in);
            tvOut = view.findViewById( R.id.tv_out);
            tvBalance = view.findViewById( R.id.tv_balance);
        }
    }
}
